<?php
// created by: alfin akhret
// related files :
// model/mdue_date.php
// view/f-due-date.php
// view/grid-due-date.php
// library/serversidedatatables.php

class Due_date extends CI_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('mdue_date');
		$this->load->model('mglobal');	     
		$this->load->model('mmaster');
		$this->load->library('form_validation');
		$this->load->library('cfpdf');
        $this->load->library('enc');

	}

	public function index()
	{
	
		$data['template'] = "shell/smooth";
		$data['main_view'] = 'f-due-date';

		$this->load->view($data['template'], $data);
		
	}

	//cari tanggal data jatuh tempo
	function get_due_date() 
	{
    $cluster_id = $this->mglobal->user_cluster($this->session->userdata("username"));
		$result = $this->mdue_date->get_due_date($cluster_id);

		//encode
        foreach ($result['aaData'] as $r => &$value) 
        {
            $value[0] = $this->enc->fogit($value[0]);
        }

		echo json_encode($result);
	}

	function defoger()
    {
    	//decode
        $result = $this->enc->defog($this->input->post('str'));
        echo $result;  
    }

	//close kasus jatuh tempo
	function close($sell_in_id)
	{
		$sell_in_id = $this->enc->defog($sell_in_id); //decode the fog.
		$sell_in_id = ltrim($sell_in_id, '0'); //trim the leading zero

		$result= $this->mdue_date->close($sell_in_id);
		$this->session->set_flashdata('message', 'record has been closed');
		redirect(base_url() . "index.php/due_date");
	}

	function topdf($sell_in_id)
	{
		//pending
	}

}